﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Project
{
    public partial class appointment : System.Web.UI.Page
    {
        string from, toa, tos, bodys, bodya;

        static string connectionString = ConfigurationManager.ConnectionStrings["StudentAdvisorString"].ConnectionString;
        SqlConnection conn = new SqlConnection(connectionString);
        SqlConnection conn2 = new SqlConnection(connectionString);
        SqlCommand comm = new SqlCommand();
        SqlCommand comm2 = new SqlCommand();
        SqlDataAdapter da = new SqlDataAdapter();
        SqlDataReader dr;
        SqlDataReader dr2;
        DataSet ds = new DataSet();
        long[] advisorid = new long[100];
        string[] days = new string[7];
        string[] time = new string[17];
        string[] weekday = new string[7];
        protected void Page_Load(object sender, EventArgs e)
        {


            from = "cencolstudentadvisor@gmail.com";
            conn = new SqlConnection(connectionString);
            conn2 = new SqlConnection(connectionString);
        }
        protected void btn_register_Click(object sender, EventArgs e)
        {

        }
        protected void button_select(string b)
        {
            if (Button1.Text == b)
            {
                Button1.Enabled = false;
                Button1.BackColor = System.Drawing.Color.Red;
            }
            if (Button2.Text == b)
            {
                Button2.Enabled = false;
                Button2.BackColor = System.Drawing.Color.Red;
            }
            if (Button3.Text == b)
            {
                Button3.Enabled = false;
                Button3.BackColor = System.Drawing.Color.Red;
            }
            if (Button4.Text == b)
            {
                Button4.Enabled = false;
                Button4.BackColor = System.Drawing.Color.Red;
            }
            if (Button5.Text == b)
            {
                Button5.Enabled = false;
                Button5.BackColor = System.Drawing.Color.Red;
            }
            if (Button6.Text == b)
            {
                Button6.Enabled = false;
                Button6.BackColor = System.Drawing.Color.Red;
            }
            if (Button7.Text == b)
            {
                Button7.Enabled = false;
                Button7.BackColor = System.Drawing.Color.Red;
            }
            if (Button8.Text == b)
            {
                Button8.Enabled = false;
                Button8.BackColor = System.Drawing.Color.Red;
            }
            if (Button9.Text == b)
            {
                Button9.Enabled = false;
                Button9.BackColor = System.Drawing.Color.Red;
            }
            if (Button10.Text == b)
            {
                Button10.Enabled = false;
                Button10.BackColor = System.Drawing.Color.Red;
            }
            if (Button11.Text == b)
            {
                Button11.Enabled = false;
                Button11.BackColor = System.Drawing.Color.Red;
            }
            if (Button12.Text == b)
            {
                Button12.Enabled = false;
                Button12.BackColor = System.Drawing.Color.Red;
            }
            if (Button13.Text == b)
            {
                Button13.Enabled = false;
                Button13.BackColor = System.Drawing.Color.Red;
            }
            if (Button14.Text == b)
            {
                Button14.Enabled = false;
                Button14.BackColor = System.Drawing.Color.Red;
            }
            if (Button15.Text == b)
            {
                Button15.Enabled = false;
                Button15.BackColor = System.Drawing.Color.Red;
            } if (Button13.Text == b)
            {
                Button16.Enabled = false;
                Button16.BackColor = System.Drawing.Color.Red;
            }
            if (Button17.Text == b)
            {
                Button17.Enabled = false;
                Button17.BackColor = System.Drawing.Color.Red;
            }
        }
        protected void button_disable()
        {
            Button1.Enabled = false;
            Button1.BackColor = System.Drawing.Color.Red;
            Button2.Enabled = false;
            Button2.BackColor = System.Drawing.Color.Red;
            Button3.Enabled = false;
            Button3.BackColor = System.Drawing.Color.Red;
            Button4.Enabled = false;
            Button4.BackColor = System.Drawing.Color.Red;
            Button5.Enabled = false;
            Button5.BackColor = System.Drawing.Color.Red;
            Button6.Enabled = false;
            Button6.BackColor = System.Drawing.Color.Red;
            Button7.Enabled = false;
            Button7.BackColor = System.Drawing.Color.Red;
            Button8.Enabled = false;
            Button8.BackColor = System.Drawing.Color.Red;
            Button9.Enabled = false;
            Button9.BackColor = System.Drawing.Color.Red;
            Button10.Enabled = false;
            Button10.BackColor = System.Drawing.Color.Red;
            Button11.Enabled = false;
            Button11.BackColor = System.Drawing.Color.Red;
            Button12.Enabled = false;
            Button12.BackColor = System.Drawing.Color.Red;
            Button13.Enabled = false;
            Button13.BackColor = System.Drawing.Color.Red;
            Button14.Enabled = false;
            Button14.BackColor = System.Drawing.Color.Red;
            Button15.Enabled = false;
            Button15.BackColor = System.Drawing.Color.Red;
            Button16.Enabled = false;
            Button16.BackColor = System.Drawing.Color.Red;
            Button17.Enabled = false;
            Button17.BackColor = System.Drawing.Color.Red;


        }
        protected void button_reset()
        {
            Button1.Enabled = true;
            Button1.BackColor = System.Drawing.Color.GreenYellow;
            Button2.Enabled = true;
            Button2.BackColor = System.Drawing.Color.GreenYellow;
            Button3.Enabled = true;
            Button3.BackColor = System.Drawing.Color.GreenYellow;
            Button4.Enabled = true;
            Button4.BackColor = System.Drawing.Color.GreenYellow;
            Button5.Enabled = true;
            Button5.BackColor = System.Drawing.Color.GreenYellow;
            Button6.Enabled = true;
            Button6.BackColor = System.Drawing.Color.GreenYellow;
            Button7.Enabled = true;
            Button7.BackColor = System.Drawing.Color.GreenYellow;
            Button8.Enabled = true;
            Button8.BackColor = System.Drawing.Color.GreenYellow;
            Button9.Enabled = true;
            Button9.BackColor = System.Drawing.Color.GreenYellow;
            Button10.Enabled = true;
            Button10.BackColor = System.Drawing.Color.GreenYellow;
            Button11.Enabled = true;
            Button11.BackColor = System.Drawing.Color.GreenYellow;
            Button12.Enabled = true;
            Button12.BackColor = System.Drawing.Color.GreenYellow;
            Button13.Enabled = true;
            Button13.BackColor = System.Drawing.Color.GreenYellow;
            Button14.Enabled = true;
            Button14.BackColor = System.Drawing.Color.GreenYellow;
            Button15.Enabled = true;
            Button15.BackColor = System.Drawing.Color.GreenYellow;
            Button16.Enabled = true;
            Button16.BackColor = System.Drawing.Color.GreenYellow;
            Button17.Enabled = true;
            Button17.BackColor = System.Drawing.Color.GreenYellow;
        }
        protected void appointment_check()
        {
            string sql2;
            conn2.Open();
            sql2 = "select advisorid,AppDate,AppStart from appointment where advisorid='" + Session["advisorid"].ToString() + "' and appDate='" + Calendar1.SelectedDate.Date.ToString() + "'";
            comm2 = new SqlCommand(sql2, conn2);
            dr2 = comm2.ExecuteReader();
            while (dr2.Read())
            {
                button_select(dr2[2].ToString());
            }
            conn2.Close();
        }
        protected void availability(string sql)
        {
            conn.Open();
            comm = new SqlCommand(sql, conn);
            dr = comm.ExecuteReader();
            while (dr.Read())
            {
                if (dr[2].ToString() == "")
                {
                    Button1.Enabled = false;
                    Button1.BackColor = System.Drawing.Color.Red;
                }
                if (dr[3].ToString() == "")
                {
                    Button2.Enabled = false;
                    Button2.BackColor = System.Drawing.Color.Red;
                }
                if (dr[4].ToString() == "")
                {
                    Button3.Enabled = false;
                    Button3.BackColor = System.Drawing.Color.Red;
                }
                if (dr[5].ToString() == "")
                {
                    Button4.Enabled = false;
                    Button4.BackColor = System.Drawing.Color.Red;
                }
                if (dr[6].ToString() == "")
                {
                    Button5.Enabled = false;
                    Button5.BackColor = System.Drawing.Color.Red;
                }
                if (dr[7].ToString() == "")
                {
                    Button6.Enabled = false;
                    Button6.BackColor = System.Drawing.Color.Red;
                }
                if (dr[8].ToString() == "")
                {
                    Button7.Enabled = false;
                    Button7.BackColor = System.Drawing.Color.Red;
                }
                if (dr[9].ToString() == "")
                {
                    Button8.Enabled = false;
                    Button9.BackColor = System.Drawing.Color.Red;
                }
                if (dr[10].ToString() == "")
                {
                    Button9.Enabled = false;
                    Button9.BackColor = System.Drawing.Color.Red;
                }
                if (dr[11].ToString() == "")
                {
                    Button10.Enabled = false;
                    Button10.BackColor = System.Drawing.Color.Red;
                }
                if (dr[12].ToString() == "")
                {
                    Button11.Enabled = false;
                    Button11.BackColor = System.Drawing.Color.Red;
                }
                if (dr[13].ToString() == "")
                {
                    Button12.Enabled = false;
                    Button12.BackColor = System.Drawing.Color.Red;
                }
                if (dr[14].ToString() == "")
                {
                    Button13.Enabled = false;
                    Button13.BackColor = System.Drawing.Color.Red;
                }
                if (dr[15].ToString() == "")
                {
                    Button14.Enabled = false;
                    Button14.BackColor = System.Drawing.Color.Red;
                }
                if (dr[16].ToString() == "")
                {
                    Button15.Enabled = false;
                    Button15.BackColor = System.Drawing.Color.Red;
                }
                if (dr[17].ToString() == "")
                {
                    Button16.Enabled = false;
                    Button16.BackColor = System.Drawing.Color.Red;
                }
                if (dr[18].ToString() == "")
                {
                    Button17.Enabled = false;
                    Button17.BackColor = System.Drawing.Color.Red;
                }
            }
            conn.Close();
        }
        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {

            Panel1.Visible = true;
            button_reset();
            conn.Open();
            comm = new SqlCommand("select advisorid,sunday,monday,tuesday,wednesday,thursday,friday,saturday,emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn);
            dr = comm.ExecuteReader();
            while (dr.Read())
            {
                Session["advisorid"] = dr[0].ToString();
                for (int i = 0; i < 7; i++)
                    weekday[i] = dr[i + 1].ToString();
                toa = dr[8].ToString();

            }
            conn.Close();
            DayOfWeek dw = Calendar1.SelectedDate.DayOfWeek;
            string day = dw.ToString("d");
            string sql;
            switch (day)
            {
                case "0":
                    if (weekday[0] == "True")
                    {
                        sql = "select advisorid,advisorname,[8:30],[9:00],[9:30],[10:00],[10:30],[11:00],[11:30],[12:00],[12:30],[13:00],[13:30],[14:00],[14:30],[15:00],[15:30],[16:00],[16:30] from Sunday where location='" + dd_location.Text + "' and advisorname='" + dd_advisorname.Text + "'";
                        availability(sql);
                        appointment_check();
                        break;
                    }
                    else
                    {
                        button_disable();
                        break;
                    }
                case "1":

                    if (weekday[1] == "True")
                    {
                        sql = "select advisorid,advisorname,[8:30],[9:00],[9:30],[10:00],[10:30],[11:00],[11:30],[12:00],[12:30],[13:00],[13:30],[14:00],[14:30],[15:00],[15:30],[16:00],[16:30] from Monday where location='" + dd_location.Text + "' and advisorname='" + dd_advisorname.Text + "'";
                        availability(sql);
                        appointment_check();
                        break;
                    }
                    else
                    {
                        button_disable();
                        break;
                    }
                case "2":
                    if (weekday[2] == "True")
                    {
                        sql = "select advisorid,advisorname,[8:30],[9:00],[9:30],[10:00],[10:30],[11:00],[11:30],[12:00],[12:30],[13:00],[13:30],[14:00],[14:30],[15:00],[15:30],[16:00],[16:30] from Tuesday where location='" + dd_location.Text + "' and advisorname='" + dd_advisorname.Text + "'";
                        availability(sql);
                        appointment_check();
                        break;
                    }
                    else
                    {
                        button_disable();
                        break;
                    }
                case "3":
                    if (weekday[3] == "True")
                    {
                        sql = "select advisorid,advisorname,[8:30],[9:00],[9:30],[10:00],[10:30],[11:00],[11:30],[12:00],[12:30],[13:00],[13:30],[14:00],[14:30],[15:00],[15:30],[16:00],[16:30] from Wednesday where location='" + dd_location.Text + "' and advisorname='" + dd_advisorname.Text + "'";
                        availability(sql);
                        appointment_check();
                        break;
                    }
                    else
                    {
                        button_disable();
                        break;
                    }
                case "4":
                    if (weekday[4] == "True")
                    {
                        sql = "select advisorid,advisorname,[8:30],[9:00],[9:30],[10:00],[10:30],[11:00],[11:30],[12:00],[12:30],[13:00],[13:30],[14:00],[14:30],[15:00],[15:30],[16:00],[16:30] from Thursday where location='" + dd_location.Text + "' and advisorname='" + dd_advisorname.Text + "'";
                        availability(sql);
                        appointment_check();
                        break;
                    }
                    else
                    {
                        button_disable();
                        break;
                    }
                case "5":
                    if (weekday[5] == "True")
                    {
                        sql = "select advisorid,advisorname,[8:30],[9:00],[9:30],[10:00],[10:30],[11:00],[11:30],[12:00],[12:30],[13:00],[13:30],[14:00],[14:30],[15:00],[15:30],[16:00],[16:30] from Friday where location='" + dd_location.Text + "' and advisorname='" + dd_advisorname.Text + "'";
                        availability(sql);
                        appointment_check();
                        break;
                    }
                    else
                    {
                        button_disable();
                        break;
                    }
                case "6":
                    if (weekday[6] == "True")
                    {
                        sql = "select advisorid,advisorname,[8:30],[9:00],[9:30],[10:00],[10:30],[11:00],[11:30],[12:00],[12:30],[13:00],[13:30],[14:00],[14:30],[15:00],[15:30],[16:00],[16:30] from Saturday where location='" + dd_location.Text + "' and advisorname='" + dd_advisorname.Text + "'";
                        availability(sql);
                        appointment_check();
                        break;
                    }
                    else
                    {
                        button_disable();
                        break;
                    }
            }


        }

        protected void dd_location_SelectedIndexChanged(object sender, EventArgs e)
        {
            Panel1.Visible = false;
            Calendar1.Visible = true;
            conn.Open();
            dd_advisorname.Items.Clear();
            comm = new SqlCommand("select name from advisorinfo where location='" + dd_location.Text + "'", conn);
            dr = comm.ExecuteReader();
            while (dr.Read())
            {
                dd_advisorname.Items.Add(dr[0].ToString());
            }
        }


        protected void Button1_Click(object sender, EventArgs e)
        {

            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {

                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button1.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button1.Enabled = false;
                    Button1.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button1.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button1.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";


        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button2.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button2.Enabled = false;
                    Button2.BackColor = System.Drawing.Color.Red;
                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button2.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button2.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button3.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button3.Enabled = false;
                    Button3.BackColor = System.Drawing.Color.Red;
                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button3.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button3.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button4_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button4.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button5.Enabled = false;
                    Button5.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button4.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button4.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button5_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button5.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button5.Enabled = false;
                    Button5.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button5.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button5.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button6_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button6.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button6.Enabled = false;
                    Button6.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button6.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button6.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";

        }
        protected void Button7_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button7.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button7.Enabled = false;
                    Button7.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button7.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button7.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button8_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button8.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button8.Enabled = false;
                    Button8.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button8.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button8.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button9_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button9.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button9.Enabled = false;
                    Button9.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button9.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button9.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button10_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button10.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button10.Enabled = false;
                    Button10.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button10.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button10.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button11_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button11.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button11.Enabled = false;
                    Button11.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button11.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button11.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button12_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button12.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button12.Enabled = false;
                    Button12.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button12.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button12.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button13_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button13.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button13.Enabled = false;
                    Button13.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button13.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button13.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button14_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button14.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button14.Enabled = false;
                    Button14.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button14.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button14.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button15_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button15.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button15.Enabled = false;
                    Button15.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button15.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button15.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button16_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button16.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button16.Enabled = false;
                    Button16.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button16.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button16.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");
                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void Button17_Click(object sender, EventArgs e)
        {
            if (txt_desc.Text != "")
            {
                if (Calendar1.SelectedDate.Date > DateTime.Now.Date)
                {
                    conn = new SqlConnection(connectionString);
                    conn.Open();
                    da = new SqlDataAdapter("insert into appointment values('" + Calendar1.SelectedDate.Date.ToShortDateString() + "','" + Button17.Text + "','" + Session["advisorid"] + "','" + Session["userID"] + "','" + dd_location.Text + "','" + txt_desc.Text + "')", conn);
                    da.Fill(ds, "appointment");
                    conn.Close();
                    Button17.Enabled = false;
                    Button17.BackColor = System.Drawing.Color.Red;

                    bodya = "Following Appointment has been scheduled\nStudent ID: " + Session["userID"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button17.Text + "";
                    bodys = "You have Successfully Scheduled an Appoint\nAdvisor ID: " + Session["advisorid"].ToString() + "\nDATE: " + Calendar1.SelectedDate.Date.ToShortDateString() + "\nTime: " + Button17.Text + "";

                    conn2.Open();
                    string sql2 = "select Email from tblUserLogin where UserId =" + Session["userID"].ToString() + "";
                    comm2 = new SqlCommand(sql2, conn2);
                    dr2 = comm2.ExecuteReader();
                    while (dr2.Read())
                    {
                        tos = dr2[0].ToString();
                    }
                    dr2.Close();

                    comm = new SqlCommand("select emailprimary from advisorinfo where name='" + dd_advisorname.Text + "'", conn2);
                    dr2 = comm.ExecuteReader();
                    while (dr2.Read())
                    {
                        toa = dr2[0].ToString();
                    }
                    conn2.Close();

                    MailHelper.SendMailMessage(from, toa, null, null, "Appointment Scheduled", bodya);
                    MailHelper.SendMailMessage(from, tos, null, null, "Appointment Scheduled", bodys);
                    Response.Redirect("Thankyou.aspx");

                }
                else
                    Label1.Text = "Invlaid Date";
            }
            else
                Label1.Text = "Please fill in the description";
        }
        protected void dd_advisorname_SelectedIndexChanged(object sender, EventArgs e)
        {
            Panel1.Visible = false;

        }
    }
}